package sort;

import java.util.Arrays;

public class SelectionSort {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 34, 56, 43, 99, 6, 7, 4, 3, 5, 6, 7, 65, 3, 2};
        selectionSort(nums);
        System.out.println(Arrays.toString(nums));

    }

    public static void selectionSort(int[] nums) {
        if (nums.length < 2 || nums == null) {
            return;
        }

        for (int i = 0; i < nums.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < nums.length; j++) {
                minIndex = nums[j] < nums[minIndex] ? j : minIndex;
            }
            swap(nums, i, minIndex);
        }
    }

    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
